]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Move drawing functions from shell-global into new shell-drawing.c file
authorColin Walters <walters@verbum.org>
Fri, 31 Jul 2009 20:32:24 +0000 (16:32 -0400)
committerColin Walters <walters@verbum.org>
Fri, 31 Jul 2009 21:26:47 +0000 (17:26 -0400)
Just to avoid shell-global.c bloat.

js/ui/appDisplay.js
js/ui/overlay.js
js/ui/widget.js
src/Makefile.am
src/shell-drawing.c [new file with mode: 0644]
src/shell-drawing.h [new file with mode: 0644]
src/shell-global.c
src/shell-global.h

index a790e3fee1213f456698bbfcc3631ee1bad0327c..9ecfc116b11837a5ef19bfc53e4a9dddd1edcbce 100644 (file)
@@ -497,11 +497,11 @@ WellDisplayItem.prototype = {
         if (this._windows.length > 0) {
             let glow = new Shell.DrawingArea({});
             glow.connect('redraw', Lang.bind(this, function (e, tex) {
-                Shell.Global.clutter_cairo_texture_draw_glow(tex,
-                                                             GLOW_COLOR.red / 255,
-                                                             GLOW_COLOR.green / 255,
-                                                             GLOW_COLOR.blue / 255,
-                                                             GLOW_COLOR.alpha / 255);
+                Shell.draw_glow(tex,
+                                GLOW_COLOR.red / 255,
+                                GLOW_COLOR.green / 255,
+                                GLOW_COLOR.blue / 255,
+                                GLOW_COLOR.alpha / 255);
             }));
             this._name.connect('notify::allocation', Lang.bind(this, function (n, alloc) {
                 let x = this._name.x;
index b2156af47119fa28715e0147a1179253d0452614..f0ea2e770d3865aed41fb5f0922c742cb930eb00 100644 (file)
@@ -258,12 +258,12 @@ Dash.prototype = {
 
         dashPane.append(dashBackground, Big.BoxPackFlags.EXPAND);
         
-        let dashLeft = global.create_horizontal_gradient(DASH_LEFT_COLOR,
-                                                         DASH_MIDDLE_COLOR);
-        let dashRight = global.create_horizontal_gradient(DASH_MIDDLE_COLOR,
-                                                          DASH_RIGHT_COLOR);
-        let dashShadow = global.create_horizontal_gradient(SHADOW_COLOR,
-                                                           TRANSPARENT_COLOR);
+        let dashLeft = Shell.create_horizontal_gradient(DASH_LEFT_COLOR,
+                                                        DASH_MIDDLE_COLOR);
+        let dashRight = Shell.create_horizontal_gradient(DASH_MIDDLE_COLOR,
+                                                         DASH_RIGHT_COLOR);
+        let dashShadow = Shell.create_horizontal_gradient(SHADOW_COLOR,
+                                                          TRANSPARENT_COLOR);
         dashShadow.set_width(SHADOW_WIDTH);
         
         dashBackground.append(dashLeft, Big.BoxPackFlags.EXPAND);
@@ -424,12 +424,12 @@ Dash.prototype = {
                                               border_color: DASH_BORDER_COLOR });
         this._resultsPane.add_actor(resultsBackground);
 
-        let resultsLeft = global.create_horizontal_gradient(PANE_LEFT_COLOR,
-                                                            PANE_MIDDLE_COLOR);
-        let resultsRight = global.create_horizontal_gradient(PANE_MIDDLE_COLOR,
-                                                             PANE_RIGHT_COLOR);
-        let resultsShadow = global.create_horizontal_gradient(SHADOW_COLOR,
-                                                              TRANSPARENT_COLOR);
+        let resultsLeft = Shell.create_horizontal_gradient(PANE_LEFT_COLOR,
+                                                           PANE_MIDDLE_COLOR);
+        let resultsRight = Shell.create_horizontal_gradient(PANE_MIDDLE_COLOR,
+                                                            PANE_RIGHT_COLOR);
+        let resultsShadow = Shell.create_horizontal_gradient(SHADOW_COLOR,
+                                                             TRANSPARENT_COLOR);
         resultsShadow.set_width(SHADOW_WIDTH);
 
         resultsBackground.append(resultsLeft, Big.BoxPackFlags.EXPAND);
@@ -460,12 +460,12 @@ Dash.prototype = {
 
         this._detailsPane.append(detailsBackground, Big.BoxPackFlags.EXPAND);
 
-        let detailsLeft = global.create_horizontal_gradient(PANE_LEFT_COLOR,
-                                                            PANE_MIDDLE_COLOR);
-        let detailsRight = global.create_horizontal_gradient(PANE_MIDDLE_COLOR,
-                                                             PANE_RIGHT_COLOR);
-        let detailsShadow = global.create_horizontal_gradient(SHADOW_COLOR,
-                                                              TRANSPARENT_COLOR);
+        let detailsLeft = Shell.create_horizontal_gradient(PANE_LEFT_COLOR,
+                                                           PANE_MIDDLE_COLOR);
+        let detailsRight = Shell.create_horizontal_gradient(PANE_MIDDLE_COLOR,
+                                                            PANE_RIGHT_COLOR);
+        let detailsShadow = Shell.create_horizontal_gradient(SHADOW_COLOR,
+                                                             TRANSPARENT_COLOR);
         detailsShadow.set_width(SHADOW_WIDTH);
         
         detailsBackground.append(detailsLeft, Big.BoxPackFlags.EXPAND);
index 4445aba220f80f17ecd5395559247aabf0ed9788..e5006d18a45ddeb0180971cc489caabd0faa0056 100644 (file)
@@ -162,9 +162,9 @@ ClockWidget.prototype = {
 
     _updateCairo: function(time) {
         let global = Shell.Global.get();
-        global.clutter_cairo_texture_draw_clock(this.collapsedActor,
-                                                time.getHours() % 12,
-                                                time.getMinutes());
+        Shell.draw_clock(this.collapsedActor,
+                         time.getHours() % 12,
+                         time.getMinutes());
     }
 };
 
index 8a7eae6e676fd85e37cae9f227f6617b27ead249..8bc6bd39a911e75c6670b51d77a5cc115b7c8d8f 100644 (file)
@@ -58,6 +58,8 @@ libgnome_shell_la_SOURCES =                   \
        shell-app-system.h                      \
        shell-arrow.c                   \
        shell-arrow.h                   \
+       shell-drawing.c            \
+       shell-drawing.h            \
        shell-drawing-area.c                    \
        shell-drawing-area.h                    \
        shell-embedded-window.c                 \
diff --git a/src/shell-drawing.c b/src/shell-drawing.c
new file mode 100644 (file)
index 0000000..58617bd
--- /dev/null
@@ -0,0 +1,180 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+#include "shell-drawing.h"
+#include <math.h>
+
+/**
+ * shell_create_vertical_gradient:
+ * @top: the color at the top
+ * @bottom: the color at the bottom
+ *
+ * Creates a vertical gradient actor.
+ *
+ * Return value: (transfer none): a #ClutterCairoTexture actor with the
+ *               gradient. The texture actor is floating, hence (transfer none).
+ */
+ClutterCairoTexture *
+shell_create_vertical_gradient (ClutterColor *top,
+                                ClutterColor *bottom)
+{
+  ClutterCairoTexture *texture;
+  cairo_t *cr;
+  cairo_pattern_t *pattern;
+
+  /* Draw the gradient on an 8x8 pixel texture. Because the gradient is drawn
+   * from the uppermost to the lowermost row, after stretching 1/16 of the
+   * texture height has the top color and 1/16 has the bottom color. The 8
+   * pixel width is chosen for reasons related to graphics hardware internals.
+   */
+  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 8));
+  cr = clutter_cairo_texture_create (texture);
+
+  pattern = cairo_pattern_create_linear (0, 0, 0, 8);
+  cairo_pattern_add_color_stop_rgba (pattern, 0,
+                                     top->red / 255.,
+                                     top->green / 255.,
+                                     top->blue / 255.,
+                                     top->alpha / 255.);
+  cairo_pattern_add_color_stop_rgba (pattern, 1,
+                                     bottom->red / 255.,
+                                     bottom->green / 255.,
+                                     bottom->blue / 255.,
+                                     bottom->alpha / 255.);
+
+  cairo_set_source (cr, pattern);
+  cairo_paint (cr);
+
+  cairo_pattern_destroy (pattern);
+  cairo_destroy (cr);
+
+  return texture;
+}
+
+/**
+ * shell_create_horizontal_gradient:
+ * @left: the color on the left
+ * @right: the color on the right
+ *
+ * Creates a horizontal gradient actor.
+ *
+ * Return value: (transfer none): a #ClutterCairoTexture actor with the
+ *               gradient. The texture actor is floating, hence (transfer none).
+ */
+ClutterCairoTexture *
+shell_create_horizontal_gradient (ClutterColor *left,
+                                  ClutterColor *right)
+{
+  ClutterCairoTexture *texture;
+  cairo_t *cr;
+  cairo_pattern_t *pattern;
+
+  /* Draw the gradient on an 8x1 pixel texture. Because the gradient is drawn
+   * from the left to the right column, after stretching 1/16 of the
+   * texture width has the left side color and 1/16 has the right side color.
+   * There is no reason to use the 8 pixel height that would be similar to the
+   * reason we are using the 8 pixel width for the vertical gradient, so we
+   * are just using the 1 pixel height instead.
+   */
+  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 1));
+  cr = clutter_cairo_texture_create (texture);
+
+  pattern = cairo_pattern_create_linear (0, 0, 8, 0);
+  cairo_pattern_add_color_stop_rgba (pattern, 0,
+                                     left->red / 255.,
+                                     left->green / 255.,
+                                     left->blue / 255.,
+                                     left->alpha / 255.);
+  cairo_pattern_add_color_stop_rgba (pattern, 1,
+                                     right->red / 255.,
+                                     right->green / 255.,
+                                     right->blue / 255.,
+                                     right->alpha / 255.);
+
+  cairo_set_source (cr, pattern);
+  cairo_paint (cr);
+
+  cairo_pattern_destroy (pattern);
+  cairo_destroy (cr);
+
+  return texture;
+}
+
+void
+shell_draw_clock (ClutterCairoTexture *texture,
+                  int                  hour,
+                  int                  minute)
+{
+  cairo_t *cr;
+  guint width, height;
+  double xc, yc, radius, hour_radius, minute_radius;
+  double angle;
+
+  clutter_cairo_texture_get_surface_size (texture, &width, &height);
+  xc = (double)width / 2;
+  yc = (double)height / 2;
+  radius = (double)(MIN(width, height)) / 2 - 2;
+  minute_radius = radius - 3;
+  hour_radius = radius / 2;
+
+  clutter_cairo_texture_clear (texture);
+  cr = clutter_cairo_texture_create (texture);
+  cairo_set_line_width (cr, 1.0);
+
+  /* Outline */
+  cairo_arc (cr, xc, yc, radius, 0.0, 2.0 * M_PI);
+  cairo_stroke (cr);
+
+  /* Hour hand. (We add a fraction to @hour for the minutes, then
+   * convert to radians, and then subtract pi/2 because cairo's origin
+   * is at 3:00, not 12:00.)
+   */
+  angle = ((hour + minute / 60.0) / 12.0) * 2.0 * M_PI - M_PI / 2.0;
+  cairo_move_to (cr, xc, yc);
+  cairo_line_to (cr,
+                 xc + hour_radius * cos (angle),
+                 yc + hour_radius * sin (angle));
+  cairo_stroke (cr);
+
+  /* Minute hand */
+  angle = (minute / 60.0) * 2.0 * M_PI - M_PI / 2.0;
+  cairo_move_to (cr, xc, yc);
+  cairo_line_to (cr,
+                 xc + minute_radius * cos (angle),
+                 yc + minute_radius * sin (angle));
+  cairo_stroke (cr);
+
+  cairo_destroy (cr);
+}
+
+void
+shell_draw_glow (ClutterCairoTexture *texture,
+                 double red,
+                 double green,
+                 double blue,
+                 double alpha)
+{
+  cairo_t *cr;
+  guint width, height;
+  cairo_pattern_t *gradient;
+
+  clutter_cairo_texture_get_surface_size (texture, &width, &height);
+
+  clutter_cairo_texture_clear (texture);
+  cr = clutter_cairo_texture_create (texture);
+
+  cairo_save (cr);
+  cairo_translate (cr, width / 2.0, height / 2.0);
+  cairo_scale (cr, width / 2.0, height / 2.0);
+
+  gradient = cairo_pattern_create_radial (0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+  cairo_pattern_add_color_stop_rgba (gradient, 0.0, red, green, blue, alpha);
+  cairo_pattern_add_color_stop_rgba (gradient, 0.7, red, green, blue, alpha * 0.7);
+  cairo_pattern_add_color_stop_rgba (gradient, 1.0, red, green, blue, alpha * 0.3);
+  cairo_set_source (cr, gradient);
+
+  cairo_arc (cr, 0.0, 0.0, 1.0, 0.0, 2.0 * M_PI);
+  cairo_fill (cr);
+  cairo_restore (cr);
+  cairo_pattern_destroy (gradient);
+  cairo_destroy (cr);
+}
diff --git a/src/shell-drawing.h b/src/shell-drawing.h
new file mode 100644 (file)
index 0000000..78c4fcf
--- /dev/null
@@ -0,0 +1,28 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+#ifndef __SHELL_DRAWING_H__
+#define __SHELL_DRAWING_H__
+
+#include <clutter/clutter.h>
+
+G_BEGIN_DECLS
+
+ClutterCairoTexture *shell_create_vertical_gradient (ClutterColor *top,
+                                                     ClutterColor *bottom);
+
+ClutterCairoTexture *shell_create_horizontal_gradient (ClutterColor *left,
+                                                       ClutterColor *right);
+
+void shell_draw_clock (ClutterCairoTexture *texture,
+                      int                  hour,
+                      int                  minute);
+
+void shell_draw_glow (ClutterCairoTexture *texture,
+                      double red,
+                      double blue,
+                      double green,
+                      double alpha);
+
+G_END_DECLS
+
+#endif /* __SHELL_GLOBAL_H__ */
index 575956c16bba4138383662fcddef5c738ab9b976..03ac1e9a5e9c42b2c3664f1243ac3d5021670e44 100644 (file)
@@ -785,102 +785,6 @@ grab_notify (GtkWidget *widget, gboolean was_grabbed, gpointer user_data)
   shell_global_set_stage_input_mode (global, global->input_mode);
 }
 
-/**
- * shell_global_create_vertical_gradient:
- * @top: the color at the top
- * @bottom: the color at the bottom
- *
- * Creates a vertical gradient actor.
- *
- * Return value: (transfer none): a #ClutterCairoTexture actor with the
- *               gradient. The texture actor is floating, hence (transfer none).
- */
-ClutterCairoTexture *
-shell_global_create_vertical_gradient (ClutterColor *top,
-                                       ClutterColor *bottom)
-{
-  ClutterCairoTexture *texture;
-  cairo_t *cr;
-  cairo_pattern_t *pattern;
-
-  /* Draw the gradient on an 8x8 pixel texture. Because the gradient is drawn
-   * from the uppermost to the lowermost row, after stretching 1/16 of the
-   * texture height has the top color and 1/16 has the bottom color. The 8
-   * pixel width is chosen for reasons related to graphics hardware internals.
-   */
-  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 8));
-  cr = clutter_cairo_texture_create (texture);
-
-  pattern = cairo_pattern_create_linear (0, 0, 0, 8);
-  cairo_pattern_add_color_stop_rgba (pattern, 0,
-                                     top->red / 255.,
-                                     top->green / 255.,
-                                     top->blue / 255.,
-                                     top->alpha / 255.);
-  cairo_pattern_add_color_stop_rgba (pattern, 1,
-                                     bottom->red / 255.,
-                                     bottom->green / 255.,
-                                     bottom->blue / 255.,
-                                     bottom->alpha / 255.);
-
-  cairo_set_source (cr, pattern);
-  cairo_paint (cr);
-
-  cairo_pattern_destroy (pattern);
-  cairo_destroy (cr);
-
-  return texture;
-}
-
-/**
- * shell_global_create_horizontal_gradient:
- * @left: the color on the left
- * @right: the color on the right
- *
- * Creates a horizontal gradient actor.
- *
- * Return value: (transfer none): a #ClutterCairoTexture actor with the
- *               gradient. The texture actor is floating, hence (transfer none).
- */
-ClutterCairoTexture *
-shell_global_create_horizontal_gradient (ClutterColor *left,
-                                         ClutterColor *right)
-{
-  ClutterCairoTexture *texture;
-  cairo_t *cr;
-  cairo_pattern_t *pattern;
-
-  /* Draw the gradient on an 8x1 pixel texture. Because the gradient is drawn
-   * from the left to the right column, after stretching 1/16 of the
-   * texture width has the left side color and 1/16 has the right side color. 
-   * There is no reason to use the 8 pixel height that would be similar to the
-   * reason we are using the 8 pixel width for the vertical gradient, so we
-   * are just using the 1 pixel height instead.
-   */
-  texture = CLUTTER_CAIRO_TEXTURE (clutter_cairo_texture_new (8, 1));
-  cr = clutter_cairo_texture_create (texture);
-
-  pattern = cairo_pattern_create_linear (0, 0, 8, 0);
-  cairo_pattern_add_color_stop_rgba (pattern, 0,
-                                     left->red / 255.,
-                                     left->green / 255.,
-                                     left->blue / 255.,
-                                     left->alpha / 255.);
-  cairo_pattern_add_color_stop_rgba (pattern, 1,
-                                     right->red / 255.,
-                                     right->green / 255.,
-                                     right->blue / 255.,
-                                     right->alpha / 255.);
-
-  cairo_set_source (cr, pattern);
-  cairo_paint (cr);
-
-  cairo_pattern_destroy (pattern);
-  cairo_destroy (cr);
-
-  return texture;
-}
-
 /*
  * Updates the global->root_pixmap actor with the root window's pixmap or fails
  * with a warning.
@@ -1104,84 +1008,3 @@ shell_global_get_max_word_width (ShellGlobal *global, ClutterActor *ref, const c
   g_strfreev (components);
   return (guint)max;
 }
-
-void
-shell_global_clutter_cairo_texture_draw_clock (ClutterCairoTexture *texture,
-                                               int                  hour,
-                                               int                  minute)
-{
-  cairo_t *cr;
-  guint width, height;
-  double xc, yc, radius, hour_radius, minute_radius;
-  double angle;
-
-  clutter_cairo_texture_get_surface_size (texture, &width, &height);
-  xc = (double)width / 2;
-  yc = (double)height / 2;
-  radius = (double)(MIN(width, height)) / 2 - 2;
-  minute_radius = radius - 3;
-  hour_radius = radius / 2;
-
-  clutter_cairo_texture_clear (texture);
-  cr = clutter_cairo_texture_create (texture);
-  cairo_set_line_width (cr, 1.0);
-
-  /* Outline */
-  cairo_arc (cr, xc, yc, radius, 0.0, 2.0 * M_PI);
-  cairo_stroke (cr);
-
-  /* Hour hand. (We add a fraction to @hour for the minutes, then
-   * convert to radians, and then subtract pi/2 because cairo's origin
-   * is at 3:00, not 12:00.)
-   */
-  angle = ((hour + minute / 60.0) / 12.0) * 2.0 * M_PI - M_PI / 2.0;
-  cairo_move_to (cr, xc, yc);
-  cairo_line_to (cr,
-                 xc + hour_radius * cos (angle),
-                 yc + hour_radius * sin (angle));
-  cairo_stroke (cr);
-
-  /* Minute hand */
-  angle = (minute / 60.0) * 2.0 * M_PI - M_PI / 2.0;
-  cairo_move_to (cr, xc, yc);
-  cairo_line_to (cr,
-                 xc + minute_radius * cos (angle),
-                 yc + minute_radius * sin (angle));
-  cairo_stroke (cr);
-
-  cairo_destroy (cr);
-}
-
-
-void
-shell_global_clutter_cairo_texture_draw_glow (ClutterCairoTexture *texture,
-                                              double red,
-                                              double green,
-                                              double blue,
-                                              double alpha)
-{
-  cairo_t *cr;
-  guint width, height;
-  cairo_pattern_t *gradient;
-
-  clutter_cairo_texture_get_surface_size (texture, &width, &height);
-
-  clutter_cairo_texture_clear (texture);
-  cr = clutter_cairo_texture_create (texture);
-
-  cairo_save (cr);
-  cairo_translate (cr, width / 2.0, height / 2.0);
-  cairo_scale (cr, width / 2.0, height / 2.0);
-
-  gradient = cairo_pattern_create_radial (0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
-  cairo_pattern_add_color_stop_rgba (gradient, 0.0, red, green, blue, alpha);
-  cairo_pattern_add_color_stop_rgba (gradient, 0.7, red, green, blue, alpha * 0.7);
-  cairo_pattern_add_color_stop_rgba (gradient, 1.0, red, green, blue, alpha * 0.3);
-  cairo_set_source (cr, gradient);
-
-  cairo_arc (cr, 0.0, 0.0, 1.0, 0.0, 2.0 * M_PI);
-  cairo_fill (cr);
-  cairo_restore (cr);
-  cairo_pattern_destroy (gradient);
-  cairo_destroy (cr);
-}
index 52cd9efb42d82f8812504adf1d72d91d7566d1b2..5d2c28d355e97d2f9bc75074c45b95a5b821111d 100644 (file)
@@ -71,28 +71,12 @@ void     shell_global_ungrab_keyboard (ShellGlobal *global);
 
 void shell_global_reexec_self (ShellGlobal *global);
 
-ClutterCairoTexture *shell_global_create_vertical_gradient (ClutterColor *top,
-                                                           ClutterColor *bottom);
-
-ClutterCairoTexture *shell_global_create_horizontal_gradient (ClutterColor *left,
-                                                             ClutterColor *right);
-
 void shell_global_format_time_relative_pretty (ShellGlobal *global, guint delta, char **text, guint *update_time);
 
 ClutterActor *shell_global_create_root_pixmap_actor (ShellGlobal *global);
 
 guint shell_global_get_max_word_width (ShellGlobal *global, ClutterActor *ref, const char *text, const char *font);
 
-void shell_global_clutter_cairo_texture_draw_clock (ClutterCairoTexture *texture,
-                                                   int                  hour,
-                                                   int                  minute);
-
-void shell_global_clutter_cairo_texture_draw_glow (ClutterCairoTexture *texture,
-                                                   double red,
-                                                   double blue,
-                                                   double green,
-                                                   double alpha);
-
 G_END_DECLS
 
 #endif /* __SHELL_GLOBAL_H__ */